/*
 *    list_ranker.cpp (WordTrending)
 *    Asif Shahidullah
 *
 *    Contains the implementation for the list rank filter
 *
 */

#include "binary_tree.hpp"
#include <string>

void rank_list (ece::tree::binary_tree<std::string>::tree_data* arr, 
                const unsigned int& size) 
{
   unsigned int last_rank = 1, iter;
   if (size == 1) {
      arr[0].rank = 1;
      return;
   }

   // Special case: first element
   if (arr[0].frequency == arr[1].frequency) {
      arr[0].rank = last_rank;
      arr[0].tie = true;
   } else {
      arr[0].rank = last_rank;
   }

   for (iter = 1; iter < size; iter++) {
      if (arr[iter].frequency == arr[iter-1].frequency) {
         arr[iter].rank = arr[iter-1].rank;
         arr[iter].tie = true;
         arr[iter-1].tie = true;
      } else 
         arr[iter].rank = ++last_rank;
   }

}
